﻿<?php
    error_reporting(E_ALL ^ E_NOTICE); 
    $ym=0;
    if(isset($_GET['ym']))
	   $ym = $_GET['ym'];
	if($ym < 1)$ym = 1;
    $bts = '';
    function huoqu($uurl,$aa){
        $mtime=0;
        if(file_exists('redian'.$aa.'.txt'))
            $mtime=filemtime('redian'.$aa.'.txt');
                
        if(date("Y-m-d",$mtime) == date("Y-m-d")){
            $bts = file_get_contents('redian'.$aa.'.txt');
            return $bts;
            
         } else{
            $ch = curl_init();
            curl_setopt ($ch, CURLOPT_URL, $uurl);
            curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
            $html = curl_exec($ch);
            curl_close($ch); 
            $bts = '';
            $zss = '';
            $html = iconv("gb2312","utf-8//IGNORE",$html);
        	for($i = 0;$i < 50;$i ++)
        	{
        		$html = strstr($html, '<a class="list-title"');
        		$html = strstr($html, '">');
        		$a = strpos($html,'/a') - 1;
        		$wenben = mb_substr($html , 0 , $a);
        		
        		$wenben = str_replace('">','',$wenben);
        
        		$bts .= $wenben.'_';
        
        	}
            if (strlen($bts) > 200) {
                file_put_contents('redian'.$aa.'.txt',$bts);
            }
            
            return $bts;
         }
    }
    switch($hqms){
        case 1:                     
            $url = 'http://top.baidu.com/buzz?b=2';               
            $bts = huoqu($url,2);
            break;
        default:
            $url = 'http://top.baidu.com/buzz?b=341';
            $bts = huoqu($url,1);      
            break;
    }
	$arr = explode('_',$bts);
	$html = file_get_contents('bangdan.htm');
	for($i = 0;$i < count($arr) && $i < 10;$i ++)
	{
		$jkm = $i;
		$url = 'http://www.baikecount.com/tz.php?word='.rawurlencode($arr[$i]).'&jkm='.$jkm.'&dizeng=d'.$dizeng;
		$html = str_replace('_anters_'.$i.'_zs','',$html);
		$html = str_replace('_anters_'.$i.'_lj',$url,$html);
		$html = str_replace('_anters_'.$i,$arr[$i],$html);
	}
    $html = str_replace('zlsbtsfzddf',$bts,$html);
	echo $html;
